import React, { Component } from 'react';

/*
  1. 取消订阅；取消定时器；取消注册事件
  2. 取消请求 
*/
class Demo extends Component{
  
  componentWillUnmount(){
    console.log("组件销毁了");
    clearInterval(this.timerId);
  }
  componentDidMount(){
    this.timerId = setInterval(()=>{
      console.log("Demo组件中的定时器");
    },1000)
  }
  render(){
    return <div>
      <h1>Demo 组件</h1>
    </div>
  }
}

class App extends Component {
  state = {
    show:true
  }
  render() {
    return (
      <div>
        {
          this.state.show?<Demo></Demo>:""
        }
        <button onClick={()=>{
          this.setState({
            show:false
          })
        }}>销毁Demo 组件</button>
      </div>
    );
  }
}

export default App;
